<?php


namespace App\controllers\admin;


use App\controllers\Base;
use Helper\Config;
use Helper\Output;
use Helper\Mysql;
use Firebase\JWT\JWT;
use Helper\Reg;

class Problem extends Base
{

    public function index($request, $response){

        $list = Mysql::getInstance()
            ->where('platform_id',$request->post['platform_id']?:$this->getUser()->platform_id)
            ->get('problem');

        return Output::json(200,$list);

    }

    public function create($request, $response){

        $data = $request->post;
        $data['create_at'] = time();
        $data['platform_id'] = $data['platform_id']?:$this->getUser()->platform_id;
        $res = Mysql::getInstance()->insert('problem',$data);
        if($res){
            return Output::json(200);
        }
        return Output::json(400);
    }


    public function edit($request, $response){

        $id = $request->post['id'];
        unset($request->post['id']);
        $res = Mysql::getInstance()->where('id',$id)->update('problem',$request->post);
        if($res){
            return Output::json(200);
        }
        return Output::json(400);
    }

}